package com.example.demo.domain;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;

@Data
@EqualsAndHashCode
@ToString
public class PageResult<T> {

    private Boolean success;

    private List<T> data;

    private long totalCount;

    private String message;

    public static <T> PageResult<T> of(List<T> list) {
        PageResult<T> pageInfo = new PageResult<>();
        pageInfo.setData(list);
        pageInfo.setSuccess(true);
        return pageInfo;
    }

    public static <T> PageResult<T> of(List<T> list, long totalCount) {
        PageResult<T> pageInfo = new PageResult<>();
        pageInfo.setSuccess(true);
        pageInfo.setData(list);
        pageInfo.setTotalCount(totalCount);
        return pageInfo;
    }

    public PageResult<T> totalCount(long totalCount) {
        this.totalCount = totalCount;
        return this;
    }

    public PageResult<T> result(List<T> data) {
        this.data = data;
        return this;
    }

    public PageResult<T> success(Boolean success) {
        this.success = success;
        return this;
    }

}
